import { LocalStorage } from "./services/local-storage.service"
import { UserService } from "./services/user.service"

// app.ts
App<IAppOption>({
  globalData: {},
  onLaunch() {
    // 展示本地存储能力
    const logs = wx.getStorageSync('logs') || []
    logs.unshift(Date.now())
    wx.setStorageSync('logs', logs)
    // 登录
    wx.login({
      success: async (response) => {
        const userInfo = await UserService.login(response.code);
        LocalStorage.setUserInfo(userInfo);
      },
    });

    const updateManager = wx.getUpdateManager();

    updateManager.onCheckForUpdate((res) => {
      console.log(res.hasUpdate)
    })

    updateManager.onUpdateReady(() => {
      wx.showModal({
        title: '有新版本',
        content: '新版本已经准备好，是否重启UA真选组？',
        success(res) {
          if (res.confirm) {
            updateManager.applyUpdate()
          }
        }
      })
    })

    updateManager.onUpdateFailed(() => {
    })

  },
})